package cn.chen.miaosha.service;

import cn.chen.miaosha.dao.GoodsDao;
import cn.chen.miaosha.domain.Goods;
import cn.chen.miaosha.domain.MiaoshaGoods;
import cn.chen.miaosha.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {

    @Autowired
    GoodsDao goodsDao;

    public List<GoodsVO> listGoodsVO(){
        return goodsDao.listGoodsVO();
    }

    public GoodsVO getGoodsVOById(long goodsId) {
        return goodsDao.getGoodsVOById(goodsId);
    }

    public boolean reduceStock(GoodsVO goods) {
        MiaoshaGoods g = new MiaoshaGoods();
        g.setGoodsId(goods.getId());
        g.setStockCount(goods.getStockCount());
        int res = goodsDao.reduceStock(g);
        return res > 0;
    }
}
